class Solution {
    public int maxSubArray(int[] nums) {
        //1. 创建dp表
        //2. 初始化
        //3. 填表
        //4. 返回值
        int n = nums.length;
        int[] dp = new int[n+1];
        dp[0] = 0;
        int ret = Integer.MIN_VALUE;
        for(int i = 1; i <= n; i++) {
            dp[i] = Math.max(nums[i-1], dp[i-1] + nums[i - 1]);
            ret = Math.max(ret, dp[i]);
        }
        return ret;
    }
}